<?php
namespace App\Admin\Controllers;

use App\Admin\Exports\MsgLogExport;
use App\Http\Controllers\Controller;
use App\Model\UserMsgLog;
use App\Model\UserMsgLogTmp;
use App\Model\UserProfile;
use App\Util\ComUtil;
use Encore\Admin\Grid;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Grid\Displayers\Actions;
use Encore\Admin\Layout\Content;
use Illuminate\Support\Facades\DB;
use App\Model\OcpcOppoLog;

class OcpcOppoLogControllers extends Controller
{
    use ModelForm;

    public function index()
    {
        $content = new Content();
        $content->header('oppo推广信息');
        $content->body($this->grid());
        return $content;
    }

    protected function grid()
    {
        $grid = new Grid(new OcpcOppoLog());
        $grid->userProfile()->user_profile_id('外部ID');

        $grid->userProfile()->nick_name('用户昵称');
        $grid->userProfile()->city('城市');
        $grid->pkg('包名')->display(function ($packageName){
            return OcpcOppoLog::PKG[$packageName];
        });
        $grid->type('类型')->display(function ($data){
            if($data == 3 || $data == 7){
                return OcpcOppoLog::TYPE[$data]."-充值金额：".round($this->pay_amount/100).'元';
            }
            return OcpcOppoLog::TYPE[$data];
        });
        $grid->is_register('是否当日注册')->display(function ($data){
            return OcpcOppoLog::IS_REG[$data];
        });
        $grid->created_at('上传时间')->display(function ($time) {
            return !$time ? '-' : date('Y-m-d H:i:s', strtotime($time));
        });
        $grid->model()->orderBy('id','desc');
        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->disableActions();
        $grid->disableCreateButton();
        $grid->filter(function ($filter) {
            $filter->expand();
            $filter->disableIdFilter();
            $filter->column(1 / 3, function ($filter) {
                $filter->between('created_at', '日期')->date();
            });
            $filter->column(1 / 3, function ($filter) {
                $filter->equal('pkg', '包名')->select(OcpcOppoLog::PKG);
            });
        });
        $grid->actions(function (Grid\Displayers\Actions $actions) {
            $actions->disableDelete();
            $actions->disableEdit();
            $actions->disableView();
        });
        return $grid;
    }
}

